# -* - coding: UTF-8 -* -
#import sys 
#reload(sys)
#sys.setdefaultencoding('utf8')

import configparser

#配置读取类
class Config:  
    def __init__(self, path):  
        self.path = path  
        self.cf = configparser.ConfigParser()  
        self.cf.read(self.path)  
    def get(self, field, key,default=''):  
        result = default  
        try:  
            result = self.cf.get(field, key,raw=True)
        except:  
            result = default  
        return result
    def get_int(self, field, key,default=0):  
        result = default  
        try:  
            result = self.cf.getint(field, key,raw=True)
        except:  
            result = default  
        return result
    def get_float(self, field, key,default=0):  
        result = default  
        try:  
            result = self.cf.getfloat(field, key,raw=True)
        except:  
            result = default  
        return result
    def get_bool(self, field, key,default=False):  
        result = default  
        try:  
            result = self.cf.getboolean(field, key,raw=True)
        except:  
            result = default  
        return result		
    def set(self, filed, key, value):  
        try:  
            self.cf.set(field, key, value)  
            cf.write(open(self.path,'w'))  
        except:  
            return False  
        return True  